package com.yys.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.yys.gulimall.order.config.AlipayTemplate;
import com.yys.gulimall.order.service.OrderService;
import com.yys.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zq
 * @version 1.0
 * @date 2021/4/7 14:44
 */
@RestController
public class PayOrderController {

    @Autowired
    private AlipayTemplate alipayTemplate;

    @Autowired
    private OrderService orderService;

    // 告诉响应类型为一个页面
    @GetMapping(value = "/payOrder",produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getorderPay(orderSn);
        // 返回一个页面,将此页面直接交给浏览器
        return alipayTemplate.pay(payVo);
    }
}
